package servlet;

import bean.Article;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet(name = "EditBlogServlet",urlPatterns = "/EditBlogServlet")
public class EditBlogServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");/*防止乱码*/
        int id=Integer.parseInt(request.getParameter("editArticleId"));/*获取博客id*/
        ArrayList<Article> articles=(ArrayList<Article>)request.getSession().getAttribute("userArticles");/*用户所有博客集合*/
        for(Article article:articles){
            if(article.getId()==id){
                request.getSession().setAttribute("editArticle",article);
                break;
            }
        }
    }
}
